/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Toolkit;

import MinaClient.MinaClient;
import MinaClient.MinaClientInterface;
import java.util.Date;
import java.util.TimerTask;
import javax.swing.JComponent;
/**
 *
 * @author bambo_000
 */
public class InfoTimerTask extends TimerTask{
     JComponent comp;
        public InfoTimerTask (JComponent comp){
            this.comp = comp;
        }
     @Override
        public void run() {

            switch(comp.getName()) {
                case "WeatherInfo":
                    sendCommand("Query;Weather;");
                    break;
                case "RunwayState":
                    sendCommand("Query;Runway;");
                    break;
                default:
                    return;
            }

           
            Date executeTime = new Date(this.scheduledExecutionTime());
            System.out.println("This task execute time" + executeTime);
        }
        
        private void sendCommand(String command) {
            MinaClientInterface mci;
            mci = new MinaClient();
            mci.createConnect("127.0.0.1",9123);
            
            String tempCommand = command+ 0 +";"+0;
            mci.sendMessage(tempCommand);
            String tempRecevieMessage = mci.receiveMessage();
            
            switch (command) {
                case "Query;Weather;":
                    new DataHandler().weatherDataHandler(tempRecevieMessage,comp);
                    break;
                case "Query;Runway;":
                    new DataHandler().runwayDataHandler(tempRecevieMessage,comp);
                    break;
            }
            
            System.out.println(tempRecevieMessage);
        }       
        
}
